insert into [$BoxTable]
select max(Stage-1),floor(leaf/2)
$MinMax
from [$BoxTable]
where Stage=$Stage
group by floor(leaf/2)